package com.shujia.flink.tf

import org.apache.flink.api.common.functions.FilterFunction
import org.apache.flink.streaming.api.scala._

object Demo3KeyBy {
  def main(args: Array[String]): Unit = {

    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    val listDS: DataStream[Int] = env.fromCollection(List(1, 2, 3, 4, 5, 6, 7, 8, 9))

    //java api
    val filterDS: DataStream[Int] = listDS.filter(new FilterFunction[Int] {
      /**
       * filter:每一条数据执行一次
       *
       * @param value ：一套数据
       * @return 返回true保留数据，返回false过滤数据
       */
      override def filter(value: Int): Boolean = {
        value % 2 == 1
      }
    })

    //scala api
    listDS.filter(i => i % 2 == 1)

    filterDS.print()

    env.execute()
  }

}
